package com.example.harmonyos_ui.slice;

import com.example.harmonyos_ui.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

/*
页面由两部分组成
    页面布局代码：xml
    后台逻辑代码：java
本文件为后台逻辑代码
 */

public class CharScrollingModeSlice extends AbilitySlice {
    private boolean is_scrolling = false;
    private Text char_scrolling_text = null;
    private Text char_scrolling_status_text = null;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_char_scrolling_mode);
        // 获取文字
        char_scrolling_text = (Text)findComponentById(ResourceTable.Id_char_scrolling_text);
        char_scrolling_status_text = (Text)findComponentById(ResourceTable.Id_char_scrolling_status_text);
        // 文字绑定点击事件
        // 单击滚动
        char_scrolling_text.setClickedListener(this::switchScrollingStatus);
    }

    // 切换滚动状态
    private void switchScrollingStatus(Component component) {
        if (is_scrolling) {
            char_scrolling_text.stopAutoScrolling();
            char_scrolling_status_text.setText("滚动停止");
            is_scrolling = !is_scrolling;
        } else {
            char_scrolling_text.startAutoScrolling();
            char_scrolling_status_text.setText("正在滚动");
            is_scrolling = !is_scrolling;
        }
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
